package sg.edu.nus.comp.qa.calculator;

import java.util.List;

import sg.edu.nus.comp.qa.utils.WordNetDictionary;

public class WordDistanceCalculatorV2 implements Calculator{
	
	public static String REGEX = " ";
	private String[] inputWords;
	
	@Override
	public double calculate(String question, String input){
		boolean flag;
		int count = 0;
		inputWords = input.split(REGEX);
		int length = inputWords.length;
		for(int i = 0; i < length; i++){
			List<String> words = WordNetDictionary.getDictionary().getSynonyms(inputWords[i]);
			int wordLength = words.size();
			flag = false;
			for(int j = 0; j < wordLength; j++){
				String[] questionWords = question.split(REGEX);
				for(int k = 0; k < questionWords.length; k++)
					if(questionWords[k].equalsIgnoreCase(words.get(j)))
						flag = true;
			}
			if(!flag)
				count++;
		}
		return 0.8 * count;
	}
}
